package com.git.bds.mr.patient.controller;

import com.git.bds.mr.page.PageParam;
import com.git.bds.mr.page.PageResult;
import com.git.bds.mr.patient.convert.PatientConvert;
import com.git.bds.mr.patient.service.PatientInfoService;
import com.git.bds.mr.records.model.dto.PatientRecordDTO;
import com.git.bds.mr.records.model.dto.RecordDTO;
import com.git.bds.mr.records.service.ch.RecordsService;
import com.git.bds.mr.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 成大事
 * @since 2022/9/26 18:49
 */
@Api(tags = "患者 病历管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/patientRecords")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PatientRecordController {

    private final PatientInfoService patientInfoService;

    private final RecordsService recordsService;

    @PostMapping("/getRecordsByPage")
    @ApiOperation("患者获取病历 分页")
    public R<PageResult<PatientRecordDTO>> getRecordsByPage(@Validated @RequestBody PageParam pageParam){
        return R.ok(patientInfoService.getRecordsByPage(pageParam));
    }

    @PostMapping("/proposedChanges")
    @ApiOperation("患者提出修改病历")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "病历id", required = true, example = "1024", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "remark", value = "编号", required = true, example = "姓名错误", dataTypeClass = String.class)
    })
    public R<Boolean> proposedChanges(
        @RequestParam("id") Long id,
        @RequestParam("remark") String remark
    ){
        return R.ok(patientInfoService.proposedChanges(id,remark));
    }

    @PostMapping("/viewMedicalRecord")
    @ApiOperation("患者查看病历详细信息")
    @ApiImplicitParam(name = "id",value = "病历id",example = "122134123",readOnly = true,dataTypeClass = Long.class)
    public R<RecordDTO> viewMedicalRecord(
            @RequestParam("id") Long id
    ){
        return R.ok(PatientConvert.INSTANCE.toRecordDTO(recordsService.getById(id)));
    }








}
